- content_for :javascript do
  initialize_admin_social_media_form("#{I18n.locale}", "#{@community.id}", "#{t('.invalid_twitter_handle')}", "#{t('.invalid_facebook_connect_id')}", "#{t('.invalid_facebook_connect_secret')}" );

- content_for :title_header do
  %h1
    = t("layouts.admin.admin")
    = "-"
    = t("admin.communities.social_media.social_media")

= render :partial => "admin/left_hand_navigation", :locals => { :links => admin_links_for(@current_community) }

.left-navi-section
  %h2= t(".social_media")
  = form_for @community, :url => social_media_admin_community_path(@community), :method => :put do |form|
    .row
      %h3= t(".logo")
      = render :partial => "layouts/info_text", :locals => { :text => t('.logo_info', :width => 1200, :height => 600)}
      = render 'layouts/thumbnail', file_field: @community.social_logo.image
      = form.fields_for :social_logo do |logo_form|
        - file_field = @community.social_logo.image
        - if file_field.file?
          .checkbox-container.file-delete-box
            - id = "attachments_destroyer_image"
            = logo_form.check_box :destroy_image, {id: id, 'attachment-destroy': true}
            = label_tag id, class: 'settings-checkbox-label' do
              = t('admin.communities.attachments.delete', title: t(".logo").downcase)
          .or-change-attachment
            = t('admin.communities.attachments.or_change', title: t(".logo").downcase)
        = logo_form.file_field(:image, :class => "file-field-button")
    .row
      %h3= t(".social_media_title")
      - facebook_preview_link = link_to(t('admin.communities.social_media.link_for_facebook'), 'https://developers.facebook.com/tools/debug/', target: '_blank')
      - linkedin_preview_link = link_to(t('admin.communities.social_media.link_for_linkedin'), 'https://www.linkedin.com/post-inspector/', target: '_blank')
      - twitter_preview_link = link_to(t('admin.communities.social_media.link_for_twitter'), 'https://cards-dev.twitter.com/validator', target: '_blank')
      - info_text = t('admin.communities.social_media.social_media_title_info', :facebook_preview_link => facebook_preview_link, :linkedin_preview_link => linkedin_preview_link, :twitter_preview_link => twitter_preview_link).html_safe
      - sorted_customizations = customizations_sorted_by_locale

      .translation-wrapper
        = render partial: "layouts/info_text", locals: {text: info_text}
        - sorted_customizations.each do |customization, language, locale|
          = form.fields_for :community_customizations, customization do |fields|
            .row
              - if sorted_customizations.size > 1
                .name-locale-label.col-2
                  = fields.label :social_media_title, language, class: 'text_field label'
              .name-locale-text_field.col-10
                = fields.text_field :social_media_title, placeholder:  "#{@community.full_name(locale)} - #{customization.slogan}", class: "text_field"

    .row
      %h3= t(".social_media_description")
      .translation-wrapper
        = render partial: "layouts/info_text", locals: {text: info_text}
        - sorted_customizations.each do |customization, language, locale|
          = form.fields_for :community_customizations, customization do |fields|
            .row
              - if sorted_customizations.size > 1
                .name-locale-label.col-2
                  = fields.label :social_media_description, language, class: 'text_field label'
              .name-locale-text_field.col-10
                = fields.text_area :social_media_description, placeholder:  "#{customization.description} - #{customization.slogan}", class: "text_field"

    .row
      %h3= t(".twitter_handle")
    .row
      .col-6
        - if display_knowledge_base_articles
          - twitter_instructions_link = link_to(t("admin.communities.social_media.twitter_instructions_link_text"), "#{knowledge_base_url}/configuration-and-how-to/how-to-configure-your-marketplaces-twitter-handle", target: :_blank)
          = render :partial => "layouts/info_text", :locals => { :text => t(".twitter_handle_info_text_with_instructions", :instructions_link => twitter_instructions_link).html_safe }
        - else
          = render :partial => "layouts/info_text", :locals => { :text => t(".twitter_handle_info_text") }
      .col-6
        = form.text_field :twitter_handle, :maxlength => "15", :class => "text_field", :placeholder => t(".twitter_handle_placeholder")
        -if @community.errors.any?
          %ul
            -@community.errors.full_messages.each do |msg|
              %li=msg
    .row
      %h3= t('.facebook_connect')
      - if display_knowledge_base_articles
        - facebook_instructions_link = link_to(t("admin.communities.social_media.facebook_instructions_link_text"), "#{knowledge_base_url}/configuration-and-how-to/how-to-configure-facebook-connect", target: :_blank)
        - facebook_dashboard_link = link_to t(".facebook_developers_dashboard"), 'https://developers.facebook.com/', target: '_blank'
        = render :partial => "layouts/info_text", :locals => { :text => t(".facebook_connect_info_text_with_instructions", :instructions_link => facebook_instructions_link, dashboard_link: facebook_dashboard_link).html_safe}
      - else
        = render :partial => "layouts/info_text", :locals => { :text => t(".facebook_connect_info_text", dashboard_link: facebook_dashboard_link).html_safe }
    .row
      .checkbox-container
        = form.check_box :facebook_connect_enabled
        = form.label :facebook_connect_enabled, t(".enable_facebook_login"), :class => "settings-checkbox-label"
    .row
      - disabled_connect = @community.facebook_connect_enabled? ? {} : {disabled: 'disabled'}
      .col-6
        = form.label :facebook_connect_id, t(".facebook_connect_id"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :facebook_connect_id, {:maxlength => "16", :class => "text_field", :placeholder => "1234567890123456"}.merge(disabled_connect)
      .col-6
        = form.label :facebook_connect_secret, t(".facebook_connect_secret"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :facebook_connect_secret, {:maxlength => "32", :class => "text_field", :placeholder => "#{Digest::MD5.hexdigest('1')}"}.merge(disabled_connect)

    .row
      %h3= t('.google_connect')
      - if display_knowledge_base_articles
        - google_instructions_link = link_to(t("admin.communities.social_media.google_instructions_link_text"), "#{knowledge_base_url}/sharetribe-go-managing-your-go-marketplace/third-party-sign-up-services/how-to-configure-google-sign-in", target: :_blank)
        - google_dashboard_link = link_to t(".google_developers_console"), 'https://developers.google.com/identity/sign-in/web/sign-in', target: '_blank'
        = render :partial => "layouts/info_text", :locals => { :text => t(".google_connect_info_text_with_instructions", :instructions_link => google_instructions_link, dashboard_link: google_dashboard_link).html_safe}
      - else
        = render :partial => "layouts/info_text", :locals => { :text => t(".google_connect_info_text", dashboard_link: google_dashboard_link).html_safe }
    .row
      .checkbox-container
        = form.check_box :google_connect_enabled
        = form.label :google_connect_enabled, t(".enable_google_login"), :class => "settings-checkbox-label"
    .row
      - disabled_connect = @community.google_connect_enabled? ? {} : {disabled: 'disabled'}
      .col-6
        = form.label :google_connect_id, t(".google_connect_id"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :google_connect_id, {:class => "text_field",
          :placeholder => "23456789-564sqsdLdglks2187pouUs275Uahdbs7of.apps.googleusercontent.com",
          required: true}.merge(disabled_connect)
      .col-6
        = form.label :google_connect_secret, t(".google_connect_secret"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :google_connect_secret, {:class => "text_field",
          :placeholder => "Qsd1ljs9qfPOA4nePsp5dglj",
          required: true}.merge(disabled_connect)

    .row
      %h3= t('.linkedin_connect')
      - if display_knowledge_base_articles
        - linkedin_instructions_link = link_to(t("admin.communities.social_media.linkedin_instructions_link_text"), "#{knowledge_base_url}/sharetribe-go-managing-your-go-marketplace/third-party-sign-up-services/how-to-configure-linkedin-sign-in", target: :_blank)
        - linkedin_dashboard_link = link_to t(".linkedin_developers_dashboard"), 'https://www.linkedin.com/developers/', target: '_blank'
        = render :partial => "layouts/info_text", :locals => { :text => t(".linkedin_connect_info_text_with_instructions", :instructions_link => linkedin_instructions_link, dashboard_link: linkedin_dashboard_link).html_safe}
      - else
        = render :partial => "layouts/info_text", :locals => { :text => t(".linkedin_connect_info_text", dashboard_link: linkedin_dashboard_link).html_safe }
    .row
      .checkbox-container
        = form.check_box :linkedin_connect_enabled
        = form.label :linkedin_connect_enabled, t(".enable_linkedin_login"), :class => "settings-checkbox-label"
    .row
      - disabled_connect = @community.linkedin_connect_enabled? ? {} : {disabled: 'disabled'}
      .col-6
        = form.label :linkedin_connect_id, t(".linkedin_connect_id"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :linkedin_connect_id, {:class => "text_field",
          :placeholder => "86xb8ms47icxgw", required: true}.merge(disabled_connect)
      .col-6
        = form.label :linkedin_connect_secret, t(".linkedin_connect_secret"), {:class => "input"}.merge(disabled_connect)
        = form.text_field :linkedin_connect_secret, {:class => "text_field",
          :placeholder => "cVjH9Q2Butjm2J90", required: true}.merge(disabled_connect)

    .row
      = form.button t("admin.communities.social_media.save")
